package com.dd.dus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.dc.entity.users.*;
import com.dd.dus.mapper.*;
import com.dd.dus.service.impl.DUserServiceImpl;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author JueDream
 * @since 2021-03-05
 */
@Slf4j
@RestController
@RequestMapping("/user/d-user")
public class DUserController {

    @Autowired
    DUserServiceImpl dUserService;

    @ApiOperation(value = "用户列表查询接口")
    @PostMapping("/queryUserList")
    public Page<DUser> queryUserList(@RequestParam int page, @RequestParam int row){
        log.info("UserServcie queryUserList start ... {},{}", page, row);
        return dUserService.queryUserList(page, row);
    }

    @ApiOperation(value = "用户查询接口")
    @PostMapping("/queryUserOne")
    public DUser queryUserOne(@RequestBody DUser user){
        log.info("UserServcie queryUserOne start ... {}", user);
        return dUserService.queryUserOne(user);
    }

    @ApiOperation(value = "用户查询接口")
    @PostMapping("/queryUserId")
    public DUser queryUserId(@RequestParam Integer userId){
        log.info("UserServcie queryUserId start ... {}", userId);
        return dUserService.queryUserId(userId);
    }

    @ApiOperation(value = "用户新增接口")
    @PostMapping("/insert")
    public Integer insert(@RequestBody DUser user){
        log.info("UserServcie insert start ... {}", user);
        return dUserService.insert(user);
    }

    @ApiOperation(value = "用户更新接口")
    @PostMapping("/updateById")
    public boolean updateById(@RequestBody DUser user){
        log.info("UserServcie updateById start ... {}", user);
        return dUserService.updateById(user);
    }

    @ApiOperation(value = "用户删除接口")
    @DeleteMapping("/delete")
    public boolean delete(@RequestParam Integer userId){
        log.info("UserServcie delete start ... {}", userId);
        return dUserService.removeById(userId);
    }

    @ApiOperation(value = "用户角色权限列表查询接口")
    @PostMapping("/queryUserInfo")
    public DUser queryUserInfo(@RequestParam Integer userId){
        log.info("UserServcie queryUserPermissionList start ... {}", userId);
        return dUserService.queryUserInfo(userId);
    }


}
